<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="author" content="wangyuguo">
    <title>操作员授权</title>
    <script language="javascript" type="text/javascript" src="../script/common.js"></script>
	<script type="text/javascript" language="JavaScript" src="../script/tree.js"></script>

    <script language="javascript" type="text/javascript">
    	
        var org,qt;
        var selectedOrg
        function load() {
            Eui.showNavigation();
            setPages(["aclview","listview","detview"]);
            org = Common.cOrg();
            searchForm.currentOrg.value = org.id;
            setSearchOrg(org);
            Common.initDict(searchForm.status,"audit_status","全部");
            createTable();
        }
		//授权信息列表
		function createTable(){
		    var columns = new Array()
		    columns[0]= {title:"姓名",render:nameFunc};
			columns[5] = {title:"角色",render:function(v, r) {
		        return "<a href=# onclick='showRole(\"" + r[6] + "\")'>" + (v ? v : "无") + "</a>"
		    }};
			columns[6] = {title:"操作",width:"10%",render:operateFunc,order:false,align:"center"}
				
			qt = new QueryTable("acl","searchForm","datalist",columns,{
				buttons:[
					{value:"增加授权",actions:onNew}
				]
			});
		}
		//数据处理方法
		function nameFunc(v, r) {//处理数据 点姓名进入查看页面
		    return "<a href=# onclick=\"onView(" + r[8] + ");return false;\">" + v + "</a>"
		}
		//操作方法
		function operateFunc(v, r) {
			if (r[9] != AuditStatus.PASSED)
				return "<a href=# onclick='onDelete(" + r[7] + ",\"" + r[0] + "\")'>删除</a>"
			else
	        	return "-";	
	    }
		
		
		//选择机构方法
		function selectOrganization(b){
			var opts = {funcType : Constants.SELORG_ALL} //获得直属子节点
		
			if (b){
				SystemMgnt.selOrg(setSearchOrg,opts);
			}else{
				SystemMgnt.selOrg(setOrg,opts);
			}
		}
		
        //searchform 选择机构 回调方法 
		function setSearchOrg(sorg){	
			searchForm.orgName.value = sorg.name;
			searchForm.organization.value = sorg.id;
		}
		
        //选择机构 回调方法
        function setOrg(sorg) {
        	selectedOrg = sorg;
            aclForm.reset();
            aclForm.organization.value = sorg.id;
            aclForm.orgName.value = sorg.name;
        }
        //选择操作员
        function selOper() {
			SystemMgnt.selOperator(function(v) {
				if (!v) return;
				aclForm.operatorName.value = v.name;
				aclForm.member.value = v.id;
			}, {orgId:selectedOrg.id})
		}


        //选择角色
        function selRolePage() {
            SystemMgnt.selRole(backRole, {orgLevel:selectedOrg.orgLevel})
        }

        //选择角色 回调方法
        function backRole(v) {
            if (!v) return;
            aclForm.ruleName.value = v.name;
            aclForm.group.value = v.id;
        }

		//新增授权
		function onNew(){
			setOrg(org);
			switchPage("aclview");
		}
		
		//删除授权
		function onDelete(id,name){
		    if (showQuestion("是否删除对【" + name + "】的授权?")) {
		        DWR.call("partyService.deleteAuditRequest", id, function() {
		            showInformation("成功删除对【" + name + "】的授权！");
		            qt.showTable();
		        });
		    }
		}
		
        //操作员授权
        function authOperator() {
            if (!checkForm(aclForm)) return;
            var gm = Common.getValues(aclForm)
            DWR.call("partyService.authorizeOperator", gm.member, gm.group, gm.organization, function() {
                showInformation("操作员授权成功")
                switchPage("listview");
                qt.showTable();
                aclForm.reset();
            },{blockScreen:true});
        }
        //查看角色明细
		function showRole(id) {
			$("opergroupview").innerHTML = "";
			switchPage("detview");
		    SystemMgnt.showGroup("opergroupview",id);
		}
		//显示明细页面和数据
		function onView(id) {
			$("opergroupview").innerHTML = "";
			switchPage("detview");
			SystemMgnt.showOperator("opergroupview",id)
		}
    </script>
</head>

<body onload="load()">
<!--页面导航-->
<div class="nav">
    <div id="nav">&nbsp;</div>
</div>
<!--查询&列表-->
<div id="listview">
	<!--查询form-->
	<div class="searchForm">
		<form id="searchForm" name="searchForm">
			<input type="hidden" name="organization">
			<input type="hidden" name="currentOrg">
			<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="label5">
				<tr>
					<td>
						<label>姓&nbsp;&nbsp;&nbsp;&nbsp;名</label>
						<input type="text" name="name" maxlength="20"/>
					</td>
					<td>
						<label>操作员编码</label>
						<input type="text" name="uniqueId" onblur="checkV(this,'number')" maxlength="10">
					</td>
					<td>
						<label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label>
						<select name="status"><option></option></select>
					</td>
				</tr>
				<tr>
					<td>
						<label>帐&nbsp;&nbsp;&nbsp;&nbsp;号</label>
						<input type="text" name="loginName" maxlength="20">
					</td>
					<td>
						<label>所属机构</label>
						<input type="text" name="orgName" maxlength="20" readonly class="readonly"><a class="orga" href="#" onclick="selectOrganization(true);">&nbsp;&nbsp;</a>
					</td>
					<td><button type="button" onclick="qt.showTable()">查 询</button></td>
				</tr>
			</table>
		</form>
	</div>

	<div id="datalist"></div>
</div>

<div id="detview" style="display:none;">
	<div id="opergroupview"></div>
	<p>
		<button type="button" onclick="switchPage('listview');">返 回</button>
	</p>
</div>
<div id="aclview" style="display:none;">
    <div class="form">
        <div class="formTitle">操作员授权</div>
        <form id="aclForm" name="aclForm">
            <input type="hidden" name="organization"/>
            <input type="hidden" name="member"/>
            <input type="hidden" name="group"/>
            <table cellSpacing="0" cellPadding="4" width="100%" border="0" class="label5">
                <tr>
                    <td><label>机构名称</label> <input type="text" name="orgName" readonly class="readonly"
                                                  onclick="selectOrganization();" onblur="checkV(this,'',true);"><a
                            class=orga href=# onclick="selectOrganization();">&nbsp;&nbsp;</a></td>
                </tr>
                <tr>
                    <td><label>操&nbsp;作&nbsp;员</label> <input type="text" name="operatorName" 
                                                              readonly class="readonly" onclick="selOper();"
                                                             onblur="checkV(this,'',true);"><a class=orga href=#
                                                                                                 onclick="selOper();">&nbsp;&nbsp;</a></td>
                </tr>
                <tr>
                    <td><label>角色名称</label> <input type="text" name="ruleName" readonly class="readonly"
                                                  onclick="selRolePage();" onblur="checkV(this,'',true);"><a
                            class=orga href=# onclick="selRolePage();">&nbsp;&nbsp;</a></td>
                </tr>
            </table>
        </form>
    </div>
    <p>
    	<button type="button" onclick="authOperator()">授 权</button>
    	<button type="button" onclick="switchPage('listview')">返 回</button>
	</p>
</div>
</body>
</html>
